/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucava.boatskeeper.shared.Boat;
import org.lucava.boatskeeper.shared.Category;

/**
 *
 * @author glenn
 */
public class MockBoatDao {

    final static Map<Integer, Boat> boats = new HashMap<Integer, Boat>();

    static {
        for (int i = 0; i < 10; i++) {
            Boat b = new Boat();
            b.setId(i);
            b.setDisplayName(" boat " + i);
            b.setCategoryId(i);
            b.setCategoryName("aCat-" + i);
            boats.put(i, b);
        }
    }

    public static void add(Boat b) {
        b.setId(boats.size() - 1);
        b.setCategoryName(MockCategoryDao.get(b.getCategoryId()).getDisplayName());

        boats.put(b.getId(), b);
    }

    public static void save(Boat b) {
        boats.get(b.getId()).setDisplayName(b.getDisplayName());
        boats.get(b.getId()).setCategoryName(MockCategoryDao.get(b.getCategoryId()).getDisplayName());
        boats.get(b.getId()).setCategoryId(b.getCategoryId());
        boats.get(b.getId()).setBoatImage(b.getBoatImage());
    }

    public static void delete(Boat b) {

        boats.remove(b.getId());
    }

    public static Boat get(Integer id) {
        return boats.get(id);
    }

    public static List<Boat> getAll() {

        return new ArrayList<Boat>(boats.values());
    }
}
